﻿//-----------------------------------------------------------------
// 该代码文件由CodeSmith的MiniAccess.cst模板创建，运行时需要MiniAccess程序集的支持。 
// 创建者  :  WuGui.Yang
// 创建时间:  2012年11月29日
//-----------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Configuration;

/// <summary>
/// 包含存取Account数据库的Access工具类和所有Entity实体类。
/// <br/>这些类均实现为Partial方式，使用时可以在单独的文件中扩展这些类的成员。
/// </summary>
namespace Ruandao.Setting.EntityAccess
{
    using Ruandao.MiniAccess;
	using Ruandao.MiniAccess.SqlServer;

    /// <summary>
	/// 该类封装了SqlServerAccess针对具体某个数据库的IAccess的一个实例，提供了存取Account数据库的工具方法。
    /// <br/>该类使用了单例模式，没有公开构造方法，只能通过GetInstance()获取类的实例。
    /// </summary>
	public sealed partial class SettingAccess : SqlServerAccess
	{
        static SettingAccess()
        {
            Type[] entityTypes = { 
typeof(SettingEntity),typeof(UserSettingEntity)            
            };
            string connectionString = GetConnectionString();
            SqlDatabase database = new SqlDatabase(connectionString);

            SettingAccess.tableMaps = new SqlServerTableMapGenerator(database).GetTableMaps(entityTypes);
        }

        private SettingAccess(string connstring)
            : base( connstring )
        { }
	}
    

	/// <summary>
	/// Table [ACT_Setting] MiniAccess Entity Class 
	/// </summary>
    [TableMap("ACT_Setting")]
	public partial class SettingEntity : EntityBase< SettingEntity >
	{
		#region Construct

		public SettingEntity():base(SettingAccess.GetInstance())
        {
            // 此处无需代码。
        }
		
		#endregion
		
		#region Get and Set Properties for All Columns.

		private int id = 0;
		public int Id
		{
			get { return this.id; }
			set
			{
                if (this.IsDelete) throw new OrMapException("不能修改已经标识为删除的实体的属性。");
                if (this.id != value)
                {
                    if ( !this.IsNew ) ChangePropertyValue("id", this.id);
                    this.id = value;
                }
			}
		}

		private string wareName = String.Empty;
		public string WareName
		{
			get { return this.wareName; }
			set
			{
                if (this.IsDelete) throw new OrMapException("不能修改已经标识为删除的实体的属性。");
                if (this.wareName != value)
                {
                    if ( !this.IsNew ) ChangePropertyValue("wareName", this.wareName);
                    this.wareName = value;
                }
			}
		}

		private string name = String.Empty;
		public string Name
		{
			get { return this.name; }
			set
			{
                if (this.IsDelete) throw new OrMapException("不能修改已经标识为删除的实体的属性。");
                if (this.name != value)
                {
                    if ( !this.IsNew ) ChangePropertyValue("name", this.name);
                    this.name = value;
                }
			}
		}

		private byte[] data;
		public byte[] Data
		{
			get { return this.data; }
			set
			{
                if (this.IsDelete) throw new OrMapException("不能修改已经标识为删除的实体的属性。");
                if (this.data != value)
                {
                    if ( !this.IsNew ) ChangePropertyValue("data", this.data);
                    this.data = value;
                }
			}
		}
		
		#endregion

		#region 获取主键所对应外键表的实体集合。
		// 函数名以Get打头，后面接着是外键表的名称，最后是Entities后缀。

		public IList< UserSettingEntity > GetUserSettingEntities()
		{
			return SettingAccess.GetInstance().SearchEntities< UserSettingEntity >("WHERE SettingId="+id);
		}
		
		#endregion
		
		#region 获取外键所对应的实体。
		// 函数名以Get打头，后面部分是外键的名称，如果外键的名称以"FK_<表名>_"开始，则只取后半部分的名称。
		
		
		#endregion

		#region static Method
		
		// 根据主键查找和删除实体的函数。
		
		public static SettingEntity Fetch(int id)
		{
            return SettingAccess.GetInstance().FetechEntity< SettingEntity >(id);
		}
		public static int Delete(int id)
		{
            return SettingAccess.GetInstance().DeleteEntity< SettingEntity >(id);
		}
		
        // 根据唯一索引（UIX_Setting_WareName_Name）查找和删除实体的函数。
		public static SettingEntity FetchByWareName_Name(string wareName,string name)
		{
			string condition = "WHERE " + 
				"WareName='" + wareName.ToString() + "'" + " AND " + 
				"Name='" + name.ToString() + "'";
            return SettingAccess.GetInstance().FindEntity< SettingEntity >("WHERE " + 
				"WareName='" + wareName.ToString() + "'" + " AND " + 
				"Name='" + name.ToString() + "'");
		} 
		public static int DeleteByWareName_Name(string wareName,string name)
		{
			string condition = "WHERE " + 
				"WareName='" + wareName.ToString() + "'" + " AND " + 
				"Name='" + name.ToString() + "'";
            return SettingAccess.GetInstance().DeleteEntities< SettingEntity >("WHERE " + 
				"WareName='" + wareName.ToString() + "'" + " AND " + 
				"Name='" + name.ToString() + "'");
		} 
		
        // 获取表中的所有记录。
		public static IList< SettingEntity > GetAllEntities()
		{
            return SettingAccess.GetInstance().SearchEntities< SettingEntity >("");
		} 
		
        // 根据条件查找表中的记录。
		public static IList< SettingEntity > SearchEntities(string condition)
		{
            return SettingAccess.GetInstance().SearchEntities< SettingEntity >(condition);
		} 
		#endregion
		
	}

	/// <summary>
	/// Table [ACT_UserSetting] MiniAccess Entity Class 
	/// </summary>
    [TableMap("ACT_UserSetting")]
	public partial class UserSettingEntity : EntityBase< UserSettingEntity >
	{
		#region Construct

		public UserSettingEntity():base(SettingAccess.GetInstance())
        {
            // 此处无需代码。
        }
		
		#endregion
		
		#region Get and Set Properties for All Columns.

		private Guid userGuid = Guid.Empty;
		public Guid UserGuid
		{
			get { return this.userGuid; }
			set
			{
                if (this.IsDelete) throw new OrMapException("不能修改已经标识为删除的实体的属性。");
                if (this.userGuid != value)
                {
                    if ( !this.IsNew ) ChangePropertyValue("userGuid", this.userGuid);
                    this.userGuid = value;
                }
			}
		}

		private int settingId = 0;
		public int SettingId
		{
			get { return this.settingId; }
			set
			{
                if (this.IsDelete) throw new OrMapException("不能修改已经标识为删除的实体的属性。");
                if (this.settingId != value)
                {
                    if ( !this.IsNew ) ChangePropertyValue("settingId", this.settingId);
                    this.settingId = value;
                }
			}
		}

		private byte[] data;
		public byte[] Data
		{
			get { return this.data; }
			set
			{
                if (this.IsDelete) throw new OrMapException("不能修改已经标识为删除的实体的属性。");
                if (this.data != value)
                {
                    if ( !this.IsNew ) ChangePropertyValue("data", this.data);
                    this.data = value;
                }
			}
		}
		
		#endregion

		#region 获取主键所对应外键表的实体集合。
		// 函数名以Get打头，后面接着是外键表的名称，最后是Entities后缀。

		
		#endregion
		
		#region 获取外键所对应的实体。
		// 函数名以Get打头，后面部分是外键的名称，如果外键的名称以"FK_<表名>_"开始，则只取后半部分的名称。
		
		public SettingEntity GetSetting()
		{
			return SettingAccess.GetInstance().FetechEntity< SettingEntity >(settingId);
		}
		
		#endregion

		#region static Method
		
		// 根据主键查找和删除实体的函数。
		
		public static UserSettingEntity Fetch(Guid userGuid,int settingId)
		{
            return SettingAccess.GetInstance().FetechEntity< UserSettingEntity >(userGuid,settingId);
		}
		public static int Delete(Guid userGuid,int settingId)
		{
            return SettingAccess.GetInstance().DeleteEntity< UserSettingEntity >(userGuid,settingId);
		}
		
		
        // 获取表中的所有记录。
		public static IList< UserSettingEntity > GetAllEntities()
		{
            return SettingAccess.GetInstance().SearchEntities< UserSettingEntity >("");
		} 
		
        // 根据条件查找表中的记录。
		public static IList< UserSettingEntity > SearchEntities(string condition)
		{
            return SettingAccess.GetInstance().SearchEntities< UserSettingEntity >(condition);
		} 
		#endregion
		
	}
}
